package neves.android.etmg.pathfinding;

import java.util.LinkedList;
import java.util.List;

import neves.android.etmg.tilemap.TileMap;

public class TileMapPathNode extends AStarNode {

	int[] location ;
	private TileMapNodeKeeper mapNodes;
	
	private boolean isGoal = false;
	

	
	public TileMapPathNode(TileMapNodeKeeper theTMap, int[] location){
		mapNodes = theTMap;
		this.location = location;
	}
	
	public void setIsGoal(boolean isG){
		isGoal = isG;
	}
	
	public boolean isGoalNode(){
		return isGoal;
	}

	@Override
	public int getCost(AStarNode node) {
		this.getEstimatedCost(node);
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getEstimatedCost(AStarNode node) {
		// TODO Auto-generated method stub
		
		int[] targetLoc = ((TileMapPathNode)node).location;
		
		int xDistance = Math.abs(targetLoc[0] - location[0]);
		int yDistance = Math.abs(targetLoc[1] - location[1]);
		
		return xDistance+yDistance;
	}

	@Override
	public List getNeigbors() {
		// TODO Auto-generated method stub
		List neighbors = new LinkedList();
		
		for(int shiftx = -1 ; shiftx < 2 ; shiftx++){
			for(int shifty = -1 ; shifty < 2 ; shifty++){
				
				TileMapPathNode neiNode = mapNodes.getNode(location[0]+shiftx, location[1]+shifty);
				
				if(neiNode!=null && !(shiftx==0 && shifty==0)){
					neighbors.add(neiNode);
				}
			}
		}
		
		
		return neighbors;
	}


	@Override
	public String getNodeInfo() {
		// TODO Auto-generated method stub
		return Integer.toString(location[0])+"_"+Integer.toString(location[1]);
	}

}
